/****************************************************************************
 *   Author:yangdongy 
 *   ReadMe:引入通用的js
 *****************************************************************************/

rootpath = Global.contextPath;

var jslib_path_prefix = rootpath + "/script/common/";
var csslib_path_prefix = rootpath + "/script/common/css/"  
//alert(jslib_path_prefix);  
//alert(csslib_path_prefix);
var importjs = function (js_file,path) {
   var js_path = path ||  jslib_path_prefix;
   document.write('<script src="'+ js_path + js_file + '" type="text/JavaScript"><\/script>');
};
var importcss = function(css_file,path){
    var css_path = path ||  csslib_path_prefix;
    document.write('<link href="'+ css_path + css_file + '" type="text/css" rel="stylesheet"/>');
};


importcss("logger.css");
importjs("json.js");
importjs("prototype.js");
importjs("jkl-floating.js");
importjs("logger.js");
importjs("select_link.js");
importjs("encoder-core.js");

// DOM2
if (typeof window.addEventListener != "undefined")
    window.addEventListener("load", function () {
    	_focusEdit();
    	//添加focus函数
    	document.body.attachEvent('onkeydown', _addOnkeyDown);
	}, false);

// IE
else if (typeof window.attachEvent != "undefined") {
    //往页面上body元素上添加默认的回车跳转功能事件
	window.attachEvent('onload', function () {
    	_focusEdit();
    	//添加focus函数
   		 document.body.attachEvent('onkeydown', _addOnkeyDown);
	});
}

/**
 * body上回车跳转功能
 * 在textarea元素上通过ctrl＋回车，进行textarea中回车编辑
 */
function _addOnkeyDown() {
   /* with (window.event) {
        var type1 = srcElement.type;
        if (keyCode == 13) {
            if (ctrlKey && type1 == "textarea") {
                //ctrl + 回车，且textarea ，编辑状态
                window.clipboardData.setData('text', '\n');
                document.execCommand("Paste");
                return;
            } else if (type1 == 'text' || type1 == 'radio' || type1 == 'checkbox' || type1 == 'textarea' || srcElement.tagName == 'SELECT' || type1 == 'password' || type1 == 'file') {
                keyCode = 9;
                return;
            }
            else if (type1 == 'button' || type1 == 'reset' || type1 == 'submit') return;
            //其他元素不执行此事件
            returnValue = false;
        }
    }*/
}

/*
*  页面load后，焦点聚焦到第一个form中的可编辑元素中
*/
function _focusEdit() {
   // with (document) {
   //     if (forms[0] != null) {
   //         for (var i = 0; i < forms[0].elements.length; i++) {
    //            var e = forms[0].elements[i];
    //            if (e.type != 'hidden' && !e.disabled && !e.readOnly) {
    //            	try{
     //               	e.focus();
     //               }catch(e){/*ignore ex*/}
     //               break;
     //           }
    //        }
    //    }
   // }
}

/*
 *  author:lianghy
 *  date:2008-7-28
 *  打开Ext的对话框
 *	参数1：跳转的地址
 *  参数2：对话框的标题信息
 *	参数3：对话框绑定初始结束的页面空间id
 *  PS:需要在页面嵌入div代码和js、css:
 *  具体代码请查看/WEB-INF/pages/sysmanagerbom/organization/organizationList.jsp
 *  " 浮动层引入js、css"部分
 *  "弹出浮动层"开始->结束部分
 *  修改记录：2008-7-31 dialog对象更改为全局；对象名称更改为：BOMExtDialog
 *	修改人：梁辉毅
 */
var BOMExtDialog;
function showExtFixDialog(actionURL,titleText,boundid,width,height){
	var dialogWidth = 650;
	var dialogHeight = 420;
	if(width != ''){
		dialogWidth = width;
	}
	if(height != ''){
		dialogHeight = height;
	}
	//alert(dialogWidth + "-----" + dialogHeight);
	var showBtn;
	var toggleTheme = function(){
	        Ext.get(document.body, true).toggleClass('xtheme-gray');
	    };
	//初始化按钮
	showBtn = Ext.get(boundid);
	var center = new Ext.ContentPanel('center', {title: titleText});
	if(!BOMExtDialog){
	    //alert("1");
	    BOMExtDialog = new Ext.LayoutDialog("operate-div-dlg", { 
	                       modal:true,
	                       width:dialogWidth,
	                       height:dialogHeight,
	                       shadow:false,
	                       minWidth:300,
	                       minHeight:300,
	                       proxyDrag: true,
	                       title: titleText + '对话框',
	                    center: {
	                        autoScroll:true
	                       }
	                   });
	     BOMExtDialog.addKeyListener(27, BOMExtDialog.hide, BOMExtDialog);
	     var layout = BOMExtDialog.getLayout();
	     layout.beginUpdate();
	     layout.add('center', center);
	     layout.endUpdate();
     }
    BOMExtDialog.show(showBtn.dom);
    
    var Divframe = Ext.getDom('dlg-body-ifm');
	var currentTime = new Date();
	//alert(currentTime.getTime());
	if(actionURL.indexOf("?") > 0){
		actionURL += "&" ;
	}else{
		actionURL += "?" 
	}
	actionURL += "timeSpam=" + currentTime.getTime();
	
    Divframe.width = BOMExtDialog.width-30;
	Divframe.height = BOMExtDialog.height;
  
	Divframe.src = actionURL;
}


function showExtDialog(actionURL,titleText,boundid){
	var dialogWidth = 650;
	var dialogHeight = 420;
	var showBtn;
	var toggleTheme = function(){
	        Ext.get(document.body, true).toggleClass('xtheme-gray');
	    };
	//初始化按钮
	showBtn = Ext.get(boundid);
	var center = new Ext.ContentPanel('center', {title: titleText});
	if(!BOMExtDialog){
	    //alert("1");
	    BOMExtDialog = new Ext.LayoutDialog("operate-div-dlg", { 
	                       modal:true,
	                       width:dialogWidth,
	                       height:dialogHeight,
	                       shadow:false,
	                       minWidth:300,
	                       minHeight:300,
	                       proxyDrag: true,
	                       title: titleText + '对话框',
	                    center: {
	                        autoScroll:true
	                        //tabPosition: 'top',
	                        //closeOnTab: true,
	                        //alwaysShowTabs: true
	                       }
	                   });
	     BOMExtDialog.addKeyListener(27, BOMExtDialog.hide, BOMExtDialog);
	               
	     var layout = BOMExtDialog.getLayout();
	     layout.beginUpdate();
	     layout.add('center', center);
	     layout.endUpdate();
     }
    BOMExtDialog.show(showBtn.dom);
    
    var Divframe = Ext.getDom('dlg-body-ifm');
	var currentTime = new Date();
	//alert(currentTime.getTime());
	if(actionURL.indexOf("?") > 0){
		actionURL += "&" ;
	}else{
		actionURL += "?" 
	}
	actionURL += "timeSpam=" + currentTime.getTime();
	
    Divframe.width = BOMExtDialog.width-30;
	Divframe.height = BOMExtDialog.height;
  
	Divframe.src = actionURL;
}

//特殊处理弹出对话框，暂时只用于礼品管理
function showExtFixDialog1(actionURL,titleText,boundid,width,height,frameHeight){
	var dialogWidth = 650;
	var dialogHeight = 420;
	if(width != ''){
		dialogWidth = width;
	}
	if(height != ''){
		dialogHeight = height;
	}
	var showBtn;
	var toggleTheme = function(){
	        Ext.get(document.body, true).toggleClass('xtheme-gray');
	    };
	//初始化按钮
	showBtn = Ext.get(boundid);
	var center = new Ext.ContentPanel('center', {title: titleText});
	if(!BOMExtDialog){
	    BOMExtDialog = new Ext.LayoutDialog("operate-div-dlg", { 
	                       modal:true,
	                       width:dialogWidth,
	                       height:dialogHeight,
	                       shadow:false,
	                       minWidth:300,
	                       minHeight:300,
	                       proxyDrag: true,
	                       title: titleText + '对话框',
	                    center: {
	                        autoScroll:true
	                       }
	                   });
	     BOMExtDialog.addKeyListener(27, BOMExtDialog.hide, BOMExtDialog);
	     var layout = BOMExtDialog.getLayout();
	     layout.beginUpdate();
	     layout.add('center', center);
	     layout.endUpdate();
     }
    BOMExtDialog.show(showBtn.dom);
    
    var Divframe = Ext.getDom('dlg-body-ifm');
	var currentTime = new Date();
	//alert(currentTime.getTime());
	if(actionURL.indexOf("?") > 0){
		actionURL += "&" ;
	}else{
		actionURL += "?" 
	}
	actionURL += "timeSpam=" + currentTime.getTime();
	
    Divframe.width = BOMExtDialog.width-60;
	Divframe.height = BOMExtDialog.height+frameHeight;
  
	Divframe.src = actionURL;
}

/*
 *  author:lianghy
 *  date:2008-7-29
 *  打开对话框公共方法
 */
function ShowWinDialog( sURL , sFeatures, param)
{ 
	//alert('showWin>>> ' + sURL);
	
	if(window.showModalDialog) {
		
		return window.showModalDialog( sURL , param, sFeatures);
	} else {
		//alert('showWin>>> ' + sURL);
		//return OpenWin( sURL , sFeatures );
		alert('请使用IE5.5以上的版本的浏览器.');
	}
	//window.showModalDialog("Sample.htm",null,"dialogHeight:591px;dialogWidth:650px;")
	//window.showModalDialog([sURL] [, vArguments] [, sFeatures])
	//sFeatures{dialogHeight; dialogLeft; dialogTop; dialogWidth; center; dialogHide; edge; help; resizable; scroll; status; unadorned}
}       

/*
 *  author:lianghy
 *  date:2008-7-31
 *	功能描述：用于弹出层的dialog的关闭和刷新发起dialog页面的列表更新.
 *  参数：ectable数据源对应查询form的id，如果不需要刷新,可以输入空字符串
 *	PS:此回调函数只用于action的callBack函数
 *  具体例子代码请查看/WEB-INF/pages/sysmanagerbom/organization/organizationList.jsp
 */
function removeBomDialog(EC2formId){
	BOMExtDialog.hide();
	if(EC2formId != ''){
		//alert("reflash table");
	    query(EC2formId);
	}
}

//不能够为中文字符验证
function isNotChinese(objVal){
	var reg=/[\u4e00-\u9fa5]/g;
	 // alert(objVal.value);
	//alert(reg.test(objVal.value));
	if(reg.test(objVal.value)){
		objVal.value=objVal.value.replace(/[\u4e00-\u9fa5]/g,"");
		// objVal.focus;
		objVal.value = null;
		return false;
	}
}



